package com.yanqu.road.server.cmd.guess.cross;

import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.CommonGuessProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.guess.CommonGuessModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.Protocol;

@CmdApi(reqMsg = CommonGuessProto.CommonGuessReceiveRewardFromCrossReqMsg.class, respMsg = CommonGuessProto.CommonGuessReceiveRewardRespMsg.class)
@Cmd(code = Protocol.S_COMMON_GUESS_RECEIVE_REWARD_FROM_CROSS,desc = "通用竞猜-跨服返回-领取竞猜奖励")
public class CommonGuessReceiveRewardFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        CommonGuessProto.CommonGuessReceiveRewardFromCrossReqMsg reqMsg = CommonGuessProto.CommonGuessReceiveRewardFromCrossReqMsg.parseFrom(packet.getBytes());
        //查询玩家
        CommonGuessProto.CommonGuessReceiveRewardRespMsg.Builder respMsg = CommonGuessProto.CommonGuessReceiveRewardRespMsg.newBuilder();
        try {
            String reward = player.getModule(CommonGuessModule.class).receiveRewardFromCross(reqMsg);
            respMsg.setRet(0);
            respMsg.setReward(reward);
        } catch (BusinessException e) {
            respMsg.setRet(e.getCode());
        }
        player.sendPacket(ClientProtocol.U_COMMON_GUESS_RECEIVE_REWARD, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
